<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper" >
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="3" :lg="7" :md="8" :sm="24">
              <edu-button type="3" @click="filter" icon="filter" title="筛选"></edu-button>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="年级" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-grade v-model="queryParam.gradeid" placeholder="请选择年级"> </j-select-grade>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <edu-button type="5" @click="searchQuery" icon="search" title="搜索" style="margin-bottom: 0"></edu-button><edu-button type="7" @click="searchReset" icon="delete" title="清除" style="margin-bottom: 0"></edu-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <edu-button @click="handleAdd" type="primary" icon="plus" title="添加"></edu-button>
<!--      <a-button @click="handleAdd" type="primary" icon="plus">添加</a-button>-->
      <edu-button
        title="启用"
        @click="batchState(1)"
        type="4"
        icon="check-circle"
      ></edu-button>

      <edu-button
        title="禁用"
        @click="batchState(0)"
        type="8"
        icon="close-circle"
      ></edu-button>
      <edu-button type="1" @click="searchQuery" icon="sync" title="刷新"></edu-button>
      <edu-button type="7" @click="recycle" icon="delete" title="回收站"></edu-button>

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDelConfirm">
            <edu-batch-delete-button ref="batchDelBtn" @del="batchDelAction" type="4"
                                     title="删除"></edu-batch-delete-button>
          </a-menu-item>
        </a-menu>
        <edu-button type="10" title="批量操作" icon="down" style="margin-bottom: 0px" rightIcon="true">
        </edu-button>
      </a-dropdown>

<!--      <a-button-->
<!--        @click="batchState(1)"-->
<!--        type="primary"-->
<!--        icon="check-circle"-->
<!--        style="background: #37d75a; color: white; border: none"-->
<!--      >启用</a-button>-->
<!--      -->
<!--      <a-button-->
<!--        @click="batchState(0)"-->
<!--        type="primary"-->
<!--        icon="close-circle"-->
<!--        style="background: #f47920; color: white; border: none"-->
<!--      >禁用</a-button>-->

<!--      <a-button @click="batchDel" type="primary" icon="delete">删除</a-button>-->
<!--      <a-button @click="searchQuery" type="primary" icon="reload">刷新</a-button>-->
<!--      <a-button @click="recycle" type="danger" icon="delete">回收站</a-button>-->
     <!--   @click="handleExportXls('ve_jw_pyfa')"-->
<!--      <a-button type="primary" icon="download" @click="handelExcel" >导出</a-button>-->
<!--      <a-upload-->
<!--        name="file"-->
<!--        :showUploadList="false"-->
<!--        :multiple="false"-->
<!--        :headers="tokenHeader"-->
<!--        :action="importExcelUrl"-->
<!--        @change="handleImportExcel"-->
<!--      >-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{x:1800}"
        :columns="columns"
        :dataSource="showDataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ fixed: true, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无此图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt="图片不存在"
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无此文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <edu-label-button type="2" @click="handleDetail(record)" title="查看"></edu-label-button>
          <a-divider type="vertical" />
          <edu-label-button type="3" @click="handleEdit(record)" title="编辑"></edu-label-button>
          <a-divider type="vertical" />
          <edu-delete-button @click="handleDelete(record.id)" type="4" title="删除"></edu-delete-button>
          <a-divider type="vertical" />
          <edu-label-button type="1" @click="handleKcjh(record)" title="课程计划"></edu-label-button>
        </span>

        <span slot="isGraduate" slot-scope="text, record">
          <a-switch
            default-checked
            @change="changeIsGraduate(record.id, checked)"
            v-model="record.isGraduate"
            :active-value="1"
            :inactive-value="0"
          />
        </span>

        <span slot="isAble" slot-scope="text, record">
          <a-switch
            default-checked
            @change="changeIsAble(record.id, checked)"
            v-model="record.isAble"
            :active-value="1"
            :inactive-value="0"
          />
        </span>
      </a-table>
    </div>

    <veJwPyfa-modal ref="modalForm" @ok="searchQuery"></veJwPyfa-modal>
    <VeJwPyfaExcelModal ref="modalExcelForm" @ok="searchQuery"></VeJwPyfaExcelModal>
    <ve-jw-pyfa-recycle-bin ref="recycle"></ve-jw-pyfa-recycle-bin>
    <ve-jw-pyfa-kcjh-modal ref="kcjhForm" @ok="searchQuery"></ve-jw-pyfa-kcjh-modal>
    <ve-jw-pyfa-filter ref="filter" @ok="searchQuery"></ve-jw-pyfa-filter>
  </a-card>
</template>

<script>
import { EduListMixin } from '@/mixins/KwglMixin'
import VeJwPyfaModal from './modules/VeJwPyfaModal'
import VeJwPyfaExcelModal from './modules/VeJwPyfaExcelModal'
import VeJwPyfaRecycleBin from './modules/VeJwPyfaRecycleBin'
import { postAction, getAction } from '@/api/manage'
import VeJwPyfaKcjhModal from './modules/VeJwPyfaKcjhModal.vue'
import JSelectGrade from '@/components/kwglbiz/JSelectGrade'
import VeJwPyfaFilter from './modules/VeJwPyfaFilter.vue'
export default {
  name: 'VeJwPyfaList',
  mixins: [EduListMixin],
  components: {
    VeJwPyfaExcelModal,
    VeJwPyfaModal,
    VeJwPyfaRecycleBin,
    VeJwPyfaKcjhModal,
    JSelectGrade,
    VeJwPyfaFilter,
  },
  data() {
    return {
      description: '培养方案管理页面',
      // 表头
      filterConfig:{
        falid:true,
      },
      columns: [
        {
          title: '名称',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: '年级',
          align: 'center',
          dataIndex: 'gradeidName',
        },
        {
          title: '学期',
          align: 'center',
          dataIndex: 'semidName',
        },
        {
          title: '专业',
          align: 'center',
          dataIndex: 'specidName',
        },
        {
          title: '学制',
          align: 'center',
          dataIndex: 'xzidName',
        },
        {
          title: '描述',
          align: 'center',
          dataIndex: 'description',
        },

        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '是否毕业',
          align: 'center',
          fixed:'right',
          dataIndex: 'isGraduate',
          scopedSlots: { customRender: 'isGraduate' },
        },
        {
          title: '是否有效',
          align: 'center',
          fixed:'right',
          dataIndex: 'isAble',
          scopedSlots: { customRender: 'isAble' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed:'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/jxgz/veJwPyfa/list',
        delete: '/jxgz/veJwPyfa/delete',
        deleteBatch: '/jxgz/veJwPyfa/deleteBatch',
        stateBatch: "/jxgz/veJwPyfa/stateBatch",
        exportXlsUrl: '/jxgz/veJwPyfa/exportXls',
        importExcelUrl: 'jxgz/veJwPyfa/importExcel',
        updateIsGraduate: '/jxgz/veJwPyfa/updateIsGraduate',
        updateIsAble: '/jxgz/veJwPyfa/updateIsAble',
      },
      dictOptions: {},
      isorter: [],
    }
  },


  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},

    //回收站
    recycle: function () {
      this.$refs.recycle.show()
      this.$refs.recycle.title = '回收站'
      this.$refs.recycle.disableSubmit = false
    },

    //查看课程计划
    handleKcjh: function (record) {
      this.$refs.kcjhForm.select(record)
      this.$refs.kcjhForm.title = '课程计划'
      this.$refs.kcjhForm.disableSubmit = false
    },
    handelExcel:function(){
      this.$refs.modalExcelForm.title = '课程计划'
      this.$refs.modalExcelForm.disableSubmit = false
    },
    //更新是否毕业
    changeIsGraduate(id, checked) {
      this.loading = true
      postAction(this.url.updateIsGraduate, { id: id })
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData()
            this.onClearSelected()
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },

    //更新是否有效
    changeIsAble(id, checked) {
      this.loading = true
      postAction(this.url.updateIsAble, { id: id })
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData()
            this.onClearSelected()
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },

    //筛选
    filter: function () {
      console.log('1111')
      this.$refs.filter.edit()
      this.$refs.filter.title = '筛选'
      this.$refs.filter.disableSubmit = false
    },

    //接收所筛选条件
    filterFormOk(gradeid, semid, isGraduate, isAble, description, createBy,zy,zyb,xz) {
      //this.jcid=id

      this.queryParam = {}
      if (gradeid != null) {
        this.queryParam.gradeid = gradeid
      }
      if (semid != null) {
        this.queryParam.semid = semid
      }
      if (isGraduate != null) {
        this.queryParam.isGraduate = isGraduate
      }
      if (isAble != null) {
        this.queryParam.isAble = isAble
      }
      if (xz != null) {
        this.queryParam.xzid = xz
      }
      if (zy != null) {
        this.queryParam.falid = zy
      }
      if (zyb != null) {
        this.queryParam.specid = zyb
      }
      // if (description != null) {
      //   this.queryParam.description = description
      // }
      // if (createBy != null) {
      //   this.queryParam.createBy = createBy
      // }

      this.loadData()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>